package cn.wei.sdd.sms.receiver;

import cn.wei.sdd.base.dto.SmsDTO;
import cn.wei.sdd.rabbitutils.constant.MQConst;
import cn.wei.sdd.sms.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: wei
 * @Date: 2022/01/24/16:27
 * MQ短信监听器
 */
@Component
@Slf4j
public class SmsReceiver {

    @Resource
    private SmsService smsService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MQConst.QUEUE_SMS_ITEM, durable = "true"),
            exchange = @Exchange(value = MQConst.EXCHANGE_TOPIC_SMS),
            key = {MQConst.ROUTING_SMS_ITEM}
    ))
    public void send(SmsDTO smsDTO){
        log.info("SmsReceiver消息监听。。。。。。");
        HashMap<String, Object> param = new HashMap<>();
        param.put("code", smsDTO.getMessage());

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        smsService.send(smsDTO.getMobile(),smsDTO.getMessage());//当前短信模板只能纯数字
    }
}

